/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       scrollbar.h

	$Header: /game/scrollbar.h $

	$NoKeywords: $

 ************************************************************************/
#ifndef SCROLLBAR_H_INCLUDED
#define SCROLLBAR_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "cached_ptr.h"
#include "game_window.h"
#include "idle_processor.h"
#include "handler.h"
#include "scrollbar_ptr.h"

class t_button;
class t_scrollbar_bitmaps;

typedef t_handler_2< t_scrollbar*, int > t_scrollbar_handler;

// ------------------------------------------------------------------
// scrollbar class
// ------------------------------------------------------------------
class t_scrollbar : public t_window, public t_idle_processor
{
public:
	// create a scrollbar, "size" pixels wide or tall, with default images.
	t_scrollbar( t_screen_point point, int size, t_window* parent, int min_value, int max_value, 
		         bool vertical = true );
	// create a scrollbar, "size" pixels wide or tall, with specified images.
	t_scrollbar( t_screen_point point, int size, t_window* parent, int min_value, int max_value, 
		         bool vertical, t_cached_ptr<t_scrollbar_bitmaps>& bitmaps );
	
	void		 down_button_down_clicked( t_button* );
	t_scrollbar_handler get_handler() const;
	int          get_position() const;
	int          get_min_value() const;
	int          get_max_value() const;
    virtual void left_button_down( t_mouse_event const& event );
    virtual void left_button_up( t_mouse_event const& event );
    virtual void mouse_leaving( t_window* old_window, t_window* new_window,
		                        t_mouse_event const& event );
	virtual void mouse_move( t_mouse_event const& event );
	virtual void on_idle();
	void         set_handler( t_scrollbar_handler function );
	void         set_limits( int min_value, int max_value );
	void		 set_max_value( int max_value );
	void         set_page_size( int arg );
	void         set_position( int arg );
	void		 up_button_down_clicked( t_button* );
protected:
	void click_up( t_button* );
	void click_down( t_button* );
	void drag( t_screen_point point );
	void init( t_screen_point point, int size, int min_value, int max_value, bool vertical,
			   t_cached_ptr<t_scrollbar_bitmaps>& bitmaps );

    t_cached_ptr<t_scrollbar_bitmaps> m_bitmaps;
	t_screen_rect        m_bar_rect;
	t_scrollbar_handler  m_handler;
	bool                 m_dragging;
	t_screen_point       m_drag_start;
	int                  m_min_value;
	int                  m_max_value;
	int                  m_page_size;
	t_window_ptr         m_thumb;
	int                  m_value;
	bool                 m_vertical;

private:
	int					 m_button_pressed;
};


inline t_scrollbar_handler t_scrollbar::get_handler() const
{
	return m_handler;
}

inline int t_scrollbar::get_position() const
{
	return m_value;
}

inline int t_scrollbar::get_min_value() const
{
	return m_min_value;
}

inline int t_scrollbar::get_max_value() const
{
	return m_max_value;
}

inline void t_scrollbar::set_handler( t_scrollbar_handler function )
{
	m_handler = function;
}

inline void t_scrollbar::set_max_value( int max_value )
{
	m_max_value = max_value;
}

inline void t_scrollbar::set_page_size( int arg )
{
	m_page_size = arg;
}

#endif // SCROLLBAR_H_INCLUDED